/**
 * <copyright>
 *
 * Copyright (c) 2011 Zeligsoft (2009) Limited
 * All rights reserved.   This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors: 
 *   Zeligsoft (2009) Limited - Initial API and implementation
 *
 * </copyright>
 *
 */
package org.omg.deployment.provider.extended;

import java.util.Collection;

import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.omg.deployment.DeploymentFactory;
import org.omg.deployment.DeploymentPackage;
import org.omg.deployment.DeploymentPlan;

/**
 * @author Toby McClean (toby@zeligsoft.com)
 *
 */
public class DeploymentPlanConstraintsItemProvider extends TransientDeploymentPlanItemProvider {

	public DeploymentPlanConstraintsItemProvider(AdapterFactory adapterFactory, DeploymentPlan deployment) {
		super(adapterFactory, deployment);
	}

	@Override
	protected Collection<? extends EStructuralFeature> getChildrenFeatures(
			Object object) {
		if(childrenFeatures == null) {
			super.getChildrenFeatures(object);
			childrenFeatures.add(DeploymentPackage.eINSTANCE.getDeploymentPlan_LocalityConstraint());
		}
		
		return childrenFeatures;
	}
	
	@Override
	public String getText(Object object) {
		if(this.getTarget() instanceof DeploymentPlan) {
			return String.format("Constraints (%d)", ((DeploymentPlan) this.getTarget()).getNumLocalityConstraint());
		}
		return "Constraints";
	}
	
	@Override
	protected void collectNewChildDescriptors(
			Collection<Object> newChildDescriptors, Object object) {
		super.collectNewChildDescriptors(newChildDescriptors, object);
		newChildDescriptors.add(createChildParameter(DeploymentPackage.DEPLOYMENT_PLAN__LOCALITY_CONSTRAINT, 
				DeploymentFactory.eINSTANCE.createPlanLocality()));
	}
	
	@Override
	public Object getImage(Object object) {
		return overlayImage(
				object,
				getResourceLocator().getImage(
						"full/obj16/PlanLocality"));
	}
}
